<template>
  <div>
    <div class="history" v-if="ifShowHistory">
      <div class="top">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="clearFn" />
      </div>
      <div class="down">
        <van-tag
          @click="tagClick(item)"
          v-for="(item, index) in historyKeywordList"
          :key="index"
          plain
          type="primary"
          >{{ item }}</van-tag
        >
      </div>
    </div>
    <div class="history">
      <div class="top">
        <h4>热门搜索</h4>
      </div>
      <div class="down">
        <van-tag
          @click="tagClick(item.keyword)"
          v-for="(item, index) in hotKeywordList"
          :key="index"
          plain
          :type="item.is_hot == 1 ? 'danger' : 'default'"
          >{{ item.keyword }}</van-tag
        >
      </div>
    </div>
  </div>
</template>

<script>
import { ClearHistory } from "../request/api";
export default {
  data() {
    return {
      ifShowHistory: true
    };
  },
  props: ["historyKeywordList", "hotKeywordList"],
  methods: {
    tagClick(item) {
      // console.log(item)
      // 子传父
      this.$emit("tagClick", item);
    },
    // 清除历史数据
    clearFn() {
      ClearHistory().then(res => {
        if (res.errno == 0) {
          // 清除历史记录
          this.$toast.success("成功文案");
          //  历史记录不显示
          setTimeout(() => {
            this.ifShowHistory = false;
          }, 2000);
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
.history {
  padding: 0 2%;
  background: #fff;
  margin-bottom: 20px;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 50px;
    background: white;
    font-size: 20px;
    h4 {
      font-weight: normal;
    }
  }
  .down {
    .van-tag {
      font-size: 14px;
      margin-right: 10px;
      margin-bottom: 10px;
      padding: 3px;
    }
  }
}
</style>
